<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <a href="#/news">新闻</a>
    |
    <a href="#/home">主页</a>

    <fieldset>
        <legend>内容</legend>
        <div id="content"></div>
    </fieldset>
</body>

</html>
<script>
    // 获取hash location.hash

    // 监听hash改变的方法 onhashchange


    window.onhashchange = function () {
        console.log(location.hash)
        switch (location.hash) {
            case "#/news":
                // console.log(content)
                content.innerHTML = "<h1>新闻</h1>"
                break
            case '#/home':
                content.innerHTML = "<h1>主页</h1>"
        }
    }
</script>